/*********************************************************
          File Name:config.h
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sat 01 Aug 2015 09:10:07 PM CST
**********************************************************/

#ifndef HASH_H_
#define HASH_H_

#define DEFAULT_NUM     309
#define CONF_PATH       "./inf.conf"

#include <unistd.h>

typedef struct list {
        char *key;
        char *val;              // handle one key, char **val for keys
        struct list *next;
} list_t;

typedef enum {
        LINE_BAD,       /* allocate memory failed */
        LINE_CMT,       /* start with '#' or '\n' */
        LINE_EOL,       /* '\0' */
        LINE_OK,        /* key-value pair */
} line_t;

typedef struct {
        char host[10];
        char port[6];
        int backlog;
        int process;
        int thread;
        char pidfile[256];
} conf_t;


void node_delete(list_t *node);

list_t *list_new(void);

void list_delete(list_t *list);

// reutrn value: 0 OK, -1 key too long, -2 can't allocate space
int list_add(list_t *list, char *key, char *value);


// return value or NULL(key not found) by giving key and key_len
char *list_getval(list_t *list, char *key);

// read all key-value pairs into a initailized hash table
int file2list(const char *path, list_t *ht, size_t *offset);

int read_conf(conf_t *cfg, size_t *offset);

#endif
